package com.codergd.gra.service;

import com.codergd.gra.bean.Administrator;
import com.codergd.gra.dao.AdministratorDao;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdministratorService {
    @Autowired
    AdministratorDao administratorDao;

    public int isLogin(String iphone, String paw){
        //管理员不存在
        if (administratorDao.selectAdmin(iphone) == null){
            return -1;
            //管理员密码错误
        }else if(!administratorDao.selectAdmin(iphone).equals(paw)){
            return 0;
        }
        //密码正确
        return 1;
    }

    public int registered(Administrator administrator){
        //管理员已存在
        if (isLogin(administrator.iphone,administrator.paw) != -1){
            return 0;
        }
        //数据插入成功
        if(administratorDao.insertAdmin(administrator) != -1) {
            return 1;
        }
        return -1;
    }
    public int insertType(String name){return administratorDao.insertType(name);}
    //根据手机号查找id
    public int selectId(String iphone){
        return administratorDao.selectId(iphone);
    }

    //根据id查找state
    public int selectState(int id){
        return administratorDao.selectState(id);
    }

    //根据状态查询
    public List<Administrator> selectByState(int state){
        return administratorDao.selectByState(state);
    }

    //根据状态查询
    public List<Administrator> selectAll(){
        return administratorDao.selectAll();
    }

    //根据账号查询
    public List<Administrator> selectByIphone(String iphone){
        return administratorDao.selectByIphone(iphone);
    }

    //两个条件
    public List<Administrator> selectTo(String iphone,int state){
        return administratorDao.selectTo(iphone,state);
    }

    //修改管理员状态
    public int updateState(int id,int state){
        return administratorDao.updateState(id,state);
    }
}
